package main

import (
	"fmt"
	"net"
	"strings"
)

func main() {
	ifis, err := net.Interfaces()
	if err != nil {
		panic(err)
	}

	ips := make([]string, 0)
	for _, ifi := range ifis {
		if ifi.Name == "lo" || ifi.Name == "docker0" {
			continue
		}

		addrs, err := ifi.Addrs()
		if err != nil {
			panic(err)
		}
		if len(addrs) == 0 {
			continue
		}

		for _, addr := range addrs {
			values := strings.Split(addr.String(), "/")
			ip := values[0]
			ips = append(ips, ip)
		}
	}

	if len(ips) == 0 {
		panic("ips is empty")
	}

	result := ""
	for _, ip := range ips {
		if strings.HasPrefix(ip, "10.") {
			result = ip
			break
		}
	}
	if result == "" {
		result = ips[0]
	}

	fmt.Println(result)
}
